Fix @task.kubernetes_cmd TaskGroup.expand mappings by templating TaskFlow args#59292
Merged
potiuk merged 1 commit intoapache:mainfrom Dec 16, 2025
Merged
Fix @task.kubernetes_cmd TaskGroup.expand mappings by templating TaskFlow args#59292potiuk merged 1 commit intoapache:mainfrom
@task.kubernetes_cmd TaskGroup.expand mappings by templating TaskFlow args#59292potiuk merged 1 commit intoapache:mainfrom
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
|
romsharon98
approved these changes
Dec 14, 2025
potiuk
approved these changes
Dec 16, 2025
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
FoxHelms
pushed a commit
to FoxHelms/airflow
that referenced
this pull request
Dec 17, 2025
Lohith625
pushed a commit
to Lohith625/airflow
that referenced
this pull request
Dec 19, 2025
54 tasks
jhgoebbert
pushed a commit
to jhgoebbert/airflow
that referenced
this pull request
Feb 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #56459
Problem
@task.kubernetes_cmdbreaks when used with TaskFlow-style mapping inside a TaskGroup.The root cause is that we didn't mark TaskFlow arguments (op_args / op_kwargs) as template_fields, thus the validation of the return value of the Python callable occurs before those fields are resolved by the TaskFlow/mapping machinery.
As a result, when
group_task.expand(...)is used, the name parameter that reaches the task (echo_cmdis the task being used in the repro linked within the issue) is still aMappedArgumentobject, and the type check inside_generate_cmdssees a non-strelement and raises theTypeError: Expected echo_cmd to return a list of strings, but got ['echo', MappedArgument(...)].Solution
I aligned
@task.kubernetes_cmdwith@task.kuberneteswith regards to how templated fields are handled, so TaskFlow mappings behave consistently. Concretely, I extendedtemplate_fieldsto includeop_argsandop_kwargsalongside the existing Kubernetes-specific fields inherited fromKubernetesPodOperator.template_fields. This ensures that TaskFlow arguments—including mapping metadata such asMappedArgumentcoming fromTaskGroup.expand(...)will be run through the normal TaskFlow resolution scheme and reach the user function as plain Python values instead of unresolved mapping objects.Finally, I add a focused unit test,
test_kubernetes_cmd_template_fields_include_taskflow_args, which creates a simple@task.kubernetes_cmdTaskFlow function insideself.dag_maker, instantiates it, and asserts that the underlying operator’stemplate_fieldsinclude at least"op_args"and"op_kwargs". This guards against future refactors accidentally dropping TaskFlow arguments fromtemplate_fieldsand reintroducing the originalMappedArgumenttype error forTaskGroup.expand(...)with@task.kubernetes_cmd.Open to discussion!